//
//  WDGoutWaitAssignTopUserInfoView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/9/7.
//

#import "WDGoutWaitAssignTopUserInfoView.h"
#import "WDArrivalServiceItemModel.h"

@interface WDGoutWaitAssignTopUserInfoView ()

@property (nonatomic, strong) WDArrivalServiceItemModel *model;

@property (nonatomic, strong) CALayer *bottomLine;

/// 电话
@property (nonatomic, strong) TYZImageTitleButton *btnPhone;

/// 标题
@property (nonatomic, strong) UILabel *titleLabel;


/// 电话
- (void)initWithBtnPhone;

/// 标题
- (void)initWithTitleLabel;

@end

@implementation WDGoutWaitAssignTopUserInfoView

- (void)initWithSubView {
    [super initWithSubView];
    
    [self initWithBottomLine];
}

- (void)initWithBottomLine {
    if (!_bottomLine) {
        CGRect frame = CGRectMake(20, self.height - 1, self.width - 40, 1);
        _bottomLine = [CALayer drawLine:self frame:frame lineColor:[UIColor colorWithHexString:@"#EEEEEE"]];
    }
}

/// 电话
- (void)initWithBtnPhone {
    UIImage *image = [UIImage imageNamed:@"ic_phon_new_blue"];
    if (!_btnPhone) {
        
        CGRect frame = CGRectMake(0, (self.height - 1 - 30) * 0.5, 0, 30);
        _btnPhone = [TYZImageTitleButton createWithImageButton:self frame:frame font:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular] target:self action:@selector(actionWithCall:) propertiesBlock:^(TYZImageTitleButton * _Nonnull button) {
            [button setImage:image forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
            [button layoutButtonWithEdgeInsetsStyle:TYZButtonEdgeInsetsStyleLeft imageTitleSpace:5];
        }];
    }
    if (self.model) {
        float width = image.size.width + 6 + [self.model.repairPhone widthForFont:self.btnPhone.titleLabel.font] + 2;
        self.btnPhone.width = width;
        self.btnPhone.left = self.width - 20 - width;
        [self.btnPhone setTitle:self.model.repairPhone forState:UIControlStateNormal];
    }
}

/// 标题
- (void)initWithTitleLabel {
    if (!_titleLabel) {
        CGRect frame = CGRectMake(20, (self.height - 1 - 30) * 0.5, self.btnPhone.left - 20 - 10, 30);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#333333"];
        }];
    }
    if (self.model) {
        self.titleLabel.text = [NSString stringWithFormat:@"客户名称：%@", objectNull(self.model.repairDriver)];
    }
}

/// 拨打电话
/// - Parameter sender: sender description
- (void)actionWithCall:(id)sender {
    if (self.touchCallPhoneBlock) {
        self.touchCallPhoneBlock();
    }
}

- (void)updateWithViewData:(id)data {
    self.model = data;
    
    /// 电话
    [self initWithBtnPhone];

    /// 标题
    [self initWithTitleLabel];
}

@end
